<?php
/*
    Id:     $Id: $
    File:   RESTView.php
    Author: John Griffin
    Date:   May 16, 2009

    Description:
*/
require_once 'lib/Error.php';

class RESTView {
    private $format = 'XML';
    private $version = '0.1';
    public function __construct ($version = '0.1', $format = 'XML') {
        $this->version = $version;
        $this->format = $format;
    }
    
    public function writeHeading ($title, $description, $created, $modified, $uri) {
        header ("Content-type: text/xml");
        print "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
        print "<response>\n";
        print "    <responseInfo>\n";
        print "        <version>{$this->version}</version>\n";
        print "        <created>${created}</created>\n";
        print "        <modified>${modified}</modified>\n";
        print "        <title>${title}</title>\n";
        print "        <description>${description}</description>\n";
        print "        <uri>${uri}</url>\n";
        print "    </responseInfo>\n";
    }
    
    public function processErrors (Error $errors) {
        print "    <errorSet>\n";
        foreach ($errors as $value) {
            print "        <error number=\"${value['number']}\" field=\"${value['field']}\">${value['message']}</error>\n";
        }
        print "    </errorSet>\n";
    }
    
    public function resultSetStart ($id, $found, $returned, $start) {
        print "    <resultSet>\n";
        print "        <resultSetId>${id}</resultSetId>\n";
        print "        <found>${found}</found>\n";
        print "        <returned>${returned}</returned>\n";
        print "        <start>${start}</start>\n";
        print "        <recordSet>\n";
        print "            <record>\n";
        print "            </record>\n";
        print "        </recordSet>\n";
    }
    
    public function resultSetEnd () {
        print "    </resultSet>\n";
    }
    
    public function writeFooter () {
        print "</response>\n";
    }
}
?>
